#include "workqueue.h"

int enQueue(workqueue_t *q, int sockfd){
    node_t *curNode = (node_t *)calloc(1, sizeof(node_t));
    ERROR_CHECK(curNode, NULL, "calloc");
    
    curNode->connectfd = sockfd;

    if(q->len == 0){
        q->head = curNode;
        q->tail = curNode;
        ++q->len;
        return 0;
    }
    q->tail->next = curNode;
    q->tail = curNode;
    ++q->len;
    return 0;
}

int deQueue(workqueue_t *q){
    if(q->len == 0){
        return 0;
    }

    node_t *curNode = q->head;
    q->head = q->head->next;
    --q->len;
    free(curNode);

    if(q->len == 0){
        q->tail = NULL;
    }
    return 0;
}

